home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Mac OS USB DDK 1.4.1 / Examples / PrinterClassDriver / DRVRGlue.a next >
Encoding:
Text File  |  2000-04-25  |  4.4 KB  |  149 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        DRVRGlue.a
  3. ;
  4. ;    Contains:    DRVR interface
  5. ;    Version:    xxx put version here xxx
  6. ;
  7.  
  8. ;
  9. ;    Copyright:     1998 by Apple Computer, Inc., all rights reserved.
  10. ;
  11. ;    File Ownership:
  12. ;
  13. ;        DRI:                xxx put dri here xxx
  14. ;
  15. ;        Other Contact:        xxx put other contact here xxx
  16. ;
  17. ;        Technology:            xxx put technology here xxx
  18. ;
  19. ;    Writers:
  20. ;
  21. ;        (JRH)    Rhoads Hollowell
  22. ;        (DF)    David Ferguson
  23. ;
  24. ;    Change History (most recent first):
  25. ;
  26. ;      <USB6>    10/20/99    JRH        Fixed a benign redefinition warning which appeared when JL added
  27. ;                                    dVMImmuneMask to Devices.i.
  28. ;      <USB5>      6/7/99    DF        convert interface to C, return proper results for immediate,
  29. ;                                    sync & async cases.
  30. ;        27 Jul 98    oja        VMImmuneMask not set so that we HoldMemory on io buffers, param blocks
  31. ;        24 Apr 98    oja        DrvrDone takes an error, passes on to JIODone
  32. ;        26 Mar 98    oja        changed driver name to ".USB--Print___"
  33. ;        28 Feb 98    oja        loosely based on Apple's StyleWriter DRVR
  34. ;
  35. ;    To Do:
  36. ;
  37.  
  38.         
  39.     BLANKS    ON
  40.     STRING    ASIS
  41.         
  42.     INCLUDE        'LowMem.a'
  43.     INCLUDE        'Devices.a'
  44. ;
  45. ;    for an explanation of VMimmune and gestalt see AsyncDriverSample 1.0b4
  46. ;
  47. dDriverGestaltEnableMask    EQU    $0004    ; See DriverGestalt.h
  48.  
  49. drvrFlags        EQU    dReadEnableMask +  dWritEnableMask + dCtlEnableMask +  dStatEnableMask
  50. drvrSystemFlags    EQU dNeedLockMask
  51.  
  52. DRVREntry        MAIN    EXPORT
  53.  
  54.                 IMPORT    DRVROpen, DRVRPrime, DRVRControl, DRVRStatus, DRVRClose
  55.  
  56. Header
  57.         dc.w    drvrFlags + drvrSystemFlags
  58.         DC.W    0        ; no run time
  59.         DC.W    0        ; no events
  60.         DC.W    0        ; no menu
  61.  
  62. ; Entry point offset table to the procs: Open, Prime, Control, Status, Close
  63.         DC.W    MyOpen        - DRVREntry  ; open routine
  64.         DC.W    MyPrime        - DRVREntry  ; prime
  65.         DC.W    MyControl    - DRVREntry  ; control
  66.         DC.W    MyStatus    - DRVREntry  ; status
  67.         DC.W    MyClose        - DRVREntry  ; close
  68.  
  69. ; Title
  70. ;        include three pad bytes so we can re-number the driver
  71.         DC.B    14                    ;Length byte
  72.         DC.B    '.USB--Print---'    ;Pad to odd # of chars, so 1st routine
  73.                                     ;  will be word-aligned.
  74.  
  75. ; Push the address of the routine we wish to call and jump to the glue
  76. ; which sets up the parameters and calls the actual driver implementation
  77. MyOpen        PEA        DRVROpen
  78.             bra.s    MyImmGlue
  79. MyPrime        PEA        DRVRPrime
  80.             bra.s    MyIOGlue
  81. MyControl    PEA        DRVRControl
  82.             bra.s    MyCtlGlue
  83. MyStatus    PEA        DRVRStatus
  84.             bra.s    MyIOGlue
  85. MyClose        PEA        DRVRClose
  86.  
  87. ;
  88. ; This glue code is used for Open/Close  - functions that only return immediate results
  89. ;
  90.  
  91. MyImmGlue
  92.             MOVEM.L    A0-A1,-(A7)                ; save params to the routine
  93.             MOVE.L    A1,-(A7)                ; pass the device control entry
  94.             MOVE.L    A0,-(A7)                ; pass the parameter block
  95.             MOVEA.L    $0010(A7),A0            ; address of routine to jump to (C calling conventions)
  96.             JSR        (A0)                    ; do it
  97.             ADDQ    #8,SP                    ; clean up stack
  98.             MOVEM.L    (A7)+,A0-A1                ; restore device parameters
  99.             ADDQ    #4,SP                    ; removed function address 
  100.             BRA.S    ImmedRTS                ; just return
  101.  
  102. MyCtlGlue
  103.             MOVEM.L    A0/A1,-(A7)                ; save params to the routine
  104.             MOVE.L    A1,-(A7)                ; pass the device control entry
  105.             MOVE.L    A0,-(A7)                ; pass the parameter block 
  106.             MOVEA.L    $0010(A7),A0            ; address of routine to jump to (C calling conventions)
  107.             JSR        (A0)                    ; do it
  108.             ADDQ    #8,SP                    ; clean up stack
  109.             MOVEM.L    (A7)+,A0/A1                ; restore device parameters
  110.             ADDQ    #4,SP                    ; removed function address 
  111.             CMPI.W    #killCode,CntrlParam.csCode(A0)
  112.             BNE.B    IOReturn                ; killIO always returns immediately
  113.             BRA.S    ImmedRTS
  114.  
  115. MyIOGlue
  116.             MOVEM.L    A0/A1,-(A7)                ; save params to the routine
  117.             MOVE.L    A1,-(A7)                ; pass the device control entry
  118.             MOVE.L    A0,-(A7)                ; pass the parameter block
  119.             MOVEA.L    $0010(A7),A0            ; address of routine to jump to (C calling conventions)
  120.             JSR        (A0)                    ; do it
  121.             ADDQ    #8,SP                    ; clean up stack
  122.             MOVEM.L    (A7)+,A0/A1                ; restore device parameters
  123.             ADDQ    #4,SP                    ; removed function address 
  124.             
  125. IOReturn    
  126.             MOVE.W    IOParam.ioTrap(A0), D1
  127.             BTST    #noQueueBit,D1            ; test for an async call
  128.             BEQ.S    Queued                    ; if not async, we're done
  129.             
  130.             TST.W    D0                        ; test async return result
  131.             BLE.B    ImmedRTS                ; if error or noErr we should return immediately
  132.             CLR.W    D0                        ; in progress gets converted to noErr
  133. ImmedRTS            
  134.             MOVE.W    D0,IOParam.ioResult(a0)    ; return the immediate result
  135.             RTS
  136.  
  137. Queued        
  138.             TST.W    D0                        ; test async return result
  139.             BLE.B    IODone                    ; if io is complete then we should return through the jIODone vector
  140.             CLR.W    D0                        ; in progress gets converted to noErr
  141.             RTS
  142. IODone            
  143.             SUBQ.W    #4,A7                    ; else get the JIODone vector
  144.             _LMGetJIODone                    ; so we can jump to it.
  145.             RTS
  146.             
  147.             ENDPROC
  148.     END
  149.